package com.lzh.dlykserver.controller;

import com.github.pagehelper.PageInfo;
import com.lzh.dlykserver.entity.TClueRemark;
import com.lzh.dlykserver.query.ClueRemarkQuery;
import com.lzh.dlykserver.result.R;
import com.lzh.dlykserver.service.ClueRemarkService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class ClueRemarkController {

    @Resource
    private ClueRemarkService clueRemarkService;


    /**
     * 添加线索记录
     * @param clueRemarkQuery
     * @param toklen
     * @return
     */
    @PostMapping("/api/clue/remark")
    public R addActivityRemark(@RequestBody ClueRemarkQuery clueRemarkQuery,
                               @RequestHeader("Authorization") String toklen) {
        clueRemarkQuery.setToken(toklen);
        int save = clueRemarkService.saveaClueRemark(clueRemarkQuery);
        return save >= 1 ? R.OK() : R.FAIL();
    }


    /**
     * 获取线索备注分页
     * @param current
     * @param clueId
     * @return
     */
    @GetMapping("/api/clue/remark")
    public R clueRemarkPage(@RequestParam(value = "current", required = false) Integer current,
                            @RequestParam("clueId") Integer clueId) {
        ClueRemarkQuery clueRemarkQuery = new ClueRemarkQuery();
        clueRemarkQuery.setClueId(clueId);
        if (current == null) {
            current = 1;
        }
        PageInfo<TClueRemark> pageInfo = clueRemarkService.getClueRemarkByPage(current, clueRemarkQuery);
        return R.OK(pageInfo);
    }


    /**
     * 获取单条线索备注记录
     * @param id
     * @return
     */
    @GetMapping("/api/clue/remark/{id}")
    public R getEditedClueRemark(@PathVariable("id") Integer id) {
        TClueRemark tClueRemark = clueRemarkService.getClueRemarkById(id);
        return R.OK(tClueRemark);
    }

    /**
     * 编辑线索备注
     * @param clueRemarkQuery
     * @param toklen
     * @return
     */
    @PutMapping("/api/clue/remark/update")
    public R editClueRemark(@RequestBody ClueRemarkQuery clueRemarkQuery,
                            @RequestHeader("Authorization") String toklen) {
        clueRemarkQuery.setToken(toklen);
        int i = clueRemarkService.editClueRemark(clueRemarkQuery);
        return i >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * 删除线索备注
     * @param id
     * @return
     */
    @DeleteMapping("/api/clue/remark/delete/{id}")
    public R delClueMark(@PathVariable("id") Integer id) {
        int i = clueRemarkService.delClueMark(id);
        return i >= 1 ? R.OK() : R.FAIL();
    }
}
